package tests;
import org.jfugue.Pattern;


public class PatternFeeder extends Thread {
	
	private Pattern pattern;

	public PatternFeeder(Pattern pattern) {
		this.pattern = pattern;
	}

	@Override
	public void run() {
		try {
			for (int i = 0; i < 10; i++) {
				String musicString = this.generateMusicString();
				System.out.println("Sent:" + musicString);
				this.pattern.add(musicString);
				Thread.sleep(1000);
			}
			System.out.println(pattern.getMusicString());
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	
	private String generateMusicString(){
		String ret = "";
		
		String[] pentatonic = {"C5", "D5", "E5", "G5", "A5"};
		String[] duration = {"h", "q", "i"};
		
		for (int i = 0; i < 10; i++) {
			//String tone = pentatonic[random(pentatonic.length)];
			//String dur = duration[random(duration.length)];
			//ret = tone + dur;
			String tone = "C5";
			String dur = "w";
			if(Math.random() < 0.5f){
				tone = "C7";
				dur = "q";
			}
			ret = ret + tone + dur + " ";
		}
		return ret.trim();
	}
	
	private int random(int limit){
		return (int) Math.floor(Math.random()*100%limit);
	}
	
	/*public static void main(String[] args) {
		Pattern p = new Pattern();
		PatternFeeder f = new PatternFeeder(p);
		for (int i = 0; i < 100; i++) {
			System.out.println(f.generateMusicString());
		}
	}*/
	
}
